package com.nifostasky.comic.common.tokenfilter;

import com.nifostasky.comic.common.threadlocal.SessionLoad;
import org.springframework.stereotype.Component;

import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;
import javax.servlet.http.HttpServletRequest;

/**
 *
 * web 请求监听器,用于释放绑定线程的数据
 * @author : Administrator
 * @date : 2021/8/18 17:41
 *
 */
@Component
public class RequestListener implements ServletRequestListener {
    /**
     * 线程销毁时,销毁绑定的用户对象,防止内存泄露
     * @param sre
     */
    @Override
    public void requestDestroyed(ServletRequestEvent sre) {
        HttpServletRequest request  = (HttpServletRequest) sre.getServletRequest();
        //移除当前线程绑定的用户数据，防止内存泄露
        SessionLoad.removeLocalData();
    }

    /**
     * 线程初始化时,不做任何处理
     * @param sre
     */
    @Override
    public void requestInitialized(ServletRequestEvent sre) {
        HttpServletRequest request  = (HttpServletRequest) sre.getServletRequest();
    }
}
